package pers.jphoebe.quartz.utils;


import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

public class Logger {

	private org.apache.log4j.Logger logger;

	
	/**
	 * 构造方法，初始化Log4j的日志对象
	 */
	private Logger(org.apache.log4j.Logger log4jLogger) {
		logger = log4jLogger;
	}

	/**
	 * 获取构造器，根据类初始化Logger对象
	 * 
	 * @param Class
	 *            Class对象
	 * @return Logger对象
	 */
	public static Logger getLogger(Class classObject) {
		return new Logger(org.apache.log4j.Logger.getLogger(classObject));
	}

	/**
	 * 获取构造器，根据类名初始化Logger对象
	 * 
	 * @param String
	 *            类名字符串
	 * @return Logger对象
	 */
	public static Logger getLogger(String loggerName) {
		return new Logger(org.apache.log4j.Logger.getLogger(loggerName));
	}

	public void debug(Object object) {
		logger.debug(object);
	}

	public void debug(Object object, Throwable e) {
		logger.debug(object, e);
	}

	public void info(String s, Object object) {
		logger.info(object);
	}

	public void info(Object object, Throwable e) {
		logger.info(object, e);
	}

	public void warn(Object object) {
		logger.warn(object);
	}

	public void warn(Object object, Throwable e) {
		logger.warn(object, e);
	}

	public void error(Object object) {
		logger.error(object);
	}

	public void error(Object object, Throwable e) {
		logger.error(object, e);
	}

	public void fatal(Object object) {
		logger.fatal(object);
	}

	public String getName() {
		return logger.getName();
	}

	public org.apache.log4j.Logger getLog4jLogger() {
		return logger;
	}

	/*public boolean equals(Logger newLogger) {
		return logger.equals(newLogger.getLog4jLogger());
	}*/

	public void fullLog(Exception ex, HttpServletRequest request) {
		logger.error("************************异常开始*******************************");
//        if(getUser() != null)
//            logger.error("当前用户id是" + getUser().getUserId());
		logger.error(ex);
		logger.error("请求地址：" + request.getRequestURL());
		Enumeration enumeration = request.getParameterNames();
		logger.error("请求参数");
		while (enumeration.hasMoreElements()) {
			String name = enumeration.nextElement().toString();
			logger.error(name + "---" + request.getParameter(name));
		}

		StackTraceElement[] error = ex.getStackTrace();
		for (StackTraceElement stackTraceElement : error) {
			logger.error(stackTraceElement.toString());
		}
		logger.error("************************异常结束*******************************");
	}
}